package com.tanhua.model.vo;

import com.tanhua.model.domain.Announcement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AnnouncementVo implements Serializable {

    private String id;
    private String title;
    private String description;
    private String createDate;

    public static AnnouncementVo init(Announcement announcement){
        AnnouncementVo announcementVo = new AnnouncementVo();
        BeanUtils.copyProperties(announcement,announcementVo);
        Date date = new Date(String.valueOf(announcement.getCreated()));
        announcementVo.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        announcementVo.setId(announcement.getId().toString());
        return announcementVo;
    }
}
